package top.songxs.yygh.task.task;

import org.joda.time.DateTime;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import top.songxs.mq.consts.MqConst;
import top.songxs.mq.service.RabbitService;

import java.util.Date;

@Component
@EnableScheduling
public class ScheduleTask {

    @Autowired
    private RabbitService rabbitService;

    @Autowired
    StringRedisTemplate redisTemplate;

    /**
     * 每天8点执行 提醒就诊
     */
    //@Scheduled(cron = "0 0 20 * * ?") 每天第20时0分0秒执行
    @Scheduled(cron = "20 * * * * ?") //测试：每分钟第20秒执行
    public void taskPatientTips() {


        String msm = redisTemplate.opsForValue().get("MSM");
        System.out.println(msm);
        if (msm == null || !msm.equals("1")) {
            System.out.println("短信提醒功能已下线！");
        } else {
            System.out.println(new Date());
            //明天的日期字符串yyyy-MM-dd
            DateTime dateTime = new DateTime().plusDays(1);
            String dateString = dateTime.toString("yyyy-MM-dd");

            //发送mq消息发送短信（第三个队列）
            rabbitService.sendMessage(MqConst.EXCHANGE_DIRECT_TASK,MqConst.ROUTING_TASK_8,dateString);
        }

    }
}
